package com.housekeeping.housekeeping.order.wxPay.controller;

import com.housekeeping.housekeeping.order.utils.ResponseEntity;
import com.housekeeping.housekeeping.order.utils.ResponseUtils;
import com.housekeeping.housekeeping.order.wxPay.config.PayConfiguration;
import com.housekeeping.housekeeping.order.wxPay.entity.Account;
import com.housekeeping.housekeeping.order.wxPay.utils.PayHelper;
import com.housekeeping.housekeeping.order.wxPay.utils.PaySate;
import com.housekeeping.housekeeping.order.wxPay.utils.WXPayCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/wxPay/query")
public class QueryOrderController extends HttpServlet {
    private PayHelper payHelper = new PayHelper(new PayConfiguration());

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String payId = req.getParameter("payId");
        //在线验证
//        Account account = AccountUtils.verifyAccount(req);
        Account account = new Account("abc123","zs","123456789");

        ResponseEntity<Integer> entity = null;
        if (payId != null && account != null) {
            entity = payHelper.queryOrderState(Long.parseLong(payId));
        } else {
            entity = ResponseEntity.error(WXPayCode.PAY_FAIL, PaySate.PAY_FAIL.getState());
        }

        ResponseUtils.deliver(resp, entity);
    }
}
